#include "TK.h"
#include "TKConfig.h"

uint8_t _getPort(uint8_t TKx)
{
    switch (TKx)
    {
    case 0:
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    case 7:
        return GPIO_Port3;
    case 8:
    case 9:
    case 10:
    case 11:
    case 12:
    case 13:
    case 14:
    case 15:
        return GPIO_Port1;
    case 16:
    case 17:
    case 18:
    case 19:
    case 20:
    case 21:
    case 22:
    case 23:
        return GPIO_Port2;
    case 24:
    case 25:
        return GPIO_Port0;
    }
    return 0;
}

uint8_t _getPin(uint8_t TKx)
{
    switch (TKx)
    {
        case 7:
        case 8:
        case 16:
        case 24:
            return GPIO_Pin0;
        case 6:
        case 9:
        case 17:
        case 25:
            return GPIO_Pin1;
        case 5:
        case 10:
        case 18:
            return GPIO_Pin2;
        case 4:
        case 11:
        case 19:
            return GPIO_Pin3;
        case 3:
        case 12:
        case 20:
            return GPIO_Pin4;
        case 2:
        case 13:
        case 21:
            return GPIO_Pin5;
        case 1:
        case 14:
        case 22:
            return GPIO_Pin6;
        case 0:
        case 15:
        case 23:
            return GPIO_Pin7;
    }
    return 0;
}

void TK_Init(uint8_t TKx)
{
    GPIO_setMode(_getPort(TKx), _getPin(TKx), GPIO_Mode_OutPP);
    // TouchKeyInit();
}
